package com.wsoft.hr.pm.controller;

import cn.hutool.core.collection.CollUtil;
import com.wsoft.bpm.bean.ApprovalChainNode;
import com.wsoft.bpm.service.WorkFlowService;
import com.wsoft.hr.pm.enums.HrProcessFlowStageEnum;
import com.wsoft.hr.pm.service.IHrPmProcessActivityService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @author zhonglj
 * @date 2024-09-19 16:05
 **/
@RestController
@Tag(name = "工作流运行时管理")
@RequestMapping("/bpm/hr")
public class HrController {
    @Resource
    private WorkFlowService workFlowService;
    @Resource
    private IHrPmProcessActivityService processActivityService;

    @Operation(summary = "hr流程启动测试", description = "hr流程启动测试")
    @PostMapping("/startProcess")
    public ResponseResult startProcess(Long memberTemplateId) {
        String processInst = processActivityService.startProcess(memberTemplateId, HrProcessFlowStageEnum.PERFORMANCE_SCORE, null);
        return ResponseResult.success("[sys.msg.success]", processInst);
    }

    @Operation(summary = "测试", description = "测试")
    @GetMapping("/test")
    public ResponseResult test(String type) {
        ApprovalChainNode zp = new ApprovalChainNode();
        zp.setApprovalName("自评");
        zp.setAssignList(CollUtil.newArrayList("1"));
        zp.setBusinessId("1");
        ApprovalChainNode hp = new ApprovalChainNode();
        hp.setApprovalName("360环评");
        hp.setAssignList(CollUtil.newArrayList("1"));
        hp.setBusinessId("2");
        ApprovalChainNode ld = new ApprovalChainNode();
        ld.setApprovalName("上级领导");
        ld.setAssignList(CollUtil.newArrayList("1"));
        ld.setBusinessId("3");

        ApprovalChainNode zp2 = new ApprovalChainNode();
        zp2.setApprovalName("自评2");
        zp2.setAssignList(CollUtil.newArrayList("1"));
        zp2.setBusinessId("11");
        ApprovalChainNode ld2 = new ApprovalChainNode();
        ld2.setApprovalName("上级领导2");
        ld2.setAssignList(CollUtil.newArrayList("1"));
        ld2.setBusinessId("33");

        ArrayList<ApprovalChainNode> approvalChainNodes = null;
        if ("1".equals(type)) {
            approvalChainNodes = CollUtil.newArrayList(zp, ld2, hp, ld);
        } else if ("2".equals(type)) {
            approvalChainNodes = CollUtil.newArrayList(zp, hp, zp2, ld);
        } else if ("3".equals(type)) {
            approvalChainNodes = CollUtil.newArrayList(hp, ld);
        } else if ("4".equals(type)) {
            approvalChainNodes = CollUtil.newArrayList(zp, hp);
        } else if ("5".equals(type)) {
            approvalChainNodes = CollUtil.newArrayList(zp, ld);
        }

        boolean b = workFlowService.resetDynamicApprovalChain("bk001", "kamui", approvalChainNodes);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

}
